const Role = require('../models/role');
const User = require('../models/user');
const bcrypt = require('bcryptjs');

const initDatabase = async () => {
    try {
        // 创建角色
        const adminRole = await Role.create({
            id: 1,
            name: 'admin',
            description: '超级管理员'
        });

        const userRole = await Role.create({
            id: 2,
            name: 'user',
            description: '普通用户'
        });

        // 创建管理员用户
        await User.create({
            name: 'admin',
            age: 25,
            email: 'admin@example.com',
            password: 'admin123',
            roleId: adminRole.id
        });

        console.log('数据库初始化完成');
    } catch (error) {
        console.error('数据库初始化失败:', error);
    }
};

module.exports = initDatabase; 